package com.bluestone.scripts;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import com.bluestone.util.Util;

public class TestSuiteTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		generateAIVRTestSuite();

	}
	public static void generateAIVRTestSuite(){
		try {
			TestSuite testsuite = new TestSuite();
			testsuite.setName("AIVR_voexo_scripts");
			
			TestCase initSIPPhoneTestCase = new TestCase();
			initSIPPhoneTestCase.setName("initSIPPhone");
			
			Command openSIPPhone = new Command();
			openSIPPhone.setName("openSIPPhone");
			
			ActionScript openSIPPhone_action = new ActionScript();
			openSIPPhone_action.setType("winrun");
			openSIPPhone_action.setPara("target", "\"C:\\Program Files\\Voxeo\\prophecy.exe\" run phone");
			openSIPPhone_action.setPara("delay", "4000");
			
			ActionScript tab_action = new ActionScript();
			tab_action.setType("inputkey");
			tab_action.setPara("target", "tab");
			tab_action.setPara("delay", "2000");
			
			openSIPPhone.putAction(openSIPPhone_action);
			openSIPPhone.putAction(tab_action);
			
			Command dialSIPPhone = new Command();
			dialSIPPhone.setName("dialSIPPhone");
			
			ActionScript altkeydown_action = new ActionScript();
			altkeydown_action.setType("altkeydown");
			dialSIPPhone.putAction(altkeydown_action);
			
			ActionScript d_action = new ActionScript();
			d_action.setType("inputkey");
			d_action.setPara("value", "d");
			dialSIPPhone.putAction(d_action);
			
			ActionScript altkeyup_action = new ActionScript();
			altkeyup_action.setType("altkeyup");
			dialSIPPhone.putAction(altkeyup_action);
			
			Command checkSIPPhone = new Command();
			checkSIPPhone.setName("checkSIPPhone");
			
			ActionScript delay_action = new ActionScript();
			delay_action.setType("delay");
			delay_action.setPara("value", "35000");
			checkSIPPhone.putAction(delay_action);
			
			ActionScript assertnotempty_action = new ActionScript();
			assertnotempty_action.setType("assertnotempty");
			checkSIPPhone.putAction(assertnotempty_action);
			
			checkSIPPhone.putAction(altkeydown_action);
			ActionScript h_action = new ActionScript();
			h_action.setType("inputkey");
			h_action.setPara("value", "h");
			checkSIPPhone.putAction(h_action);			
			checkSIPPhone.putAction(altkeyup_action);
			
			ActionScript assertcleardata_action = new ActionScript();
			assertcleardata_action.setType("assertcleardata");
			checkSIPPhone.putAction(assertcleardata_action);
			
			ActionScript delay5000_action = new ActionScript();
			delay5000_action.setType("delay");
			delay5000_action.setPara("value", "5000");
			checkSIPPhone.putAction(delay5000_action);
			
			initSIPPhoneTestCase.putCommand(openSIPPhone);
			initSIPPhoneTestCase.putCommand(dialSIPPhone);
			initSIPPhoneTestCase.putCommand(checkSIPPhone);
			
			TestCase userloginsuccessfulTestCase = new TestCase();
			userloginsuccessfulTestCase.setName("userloginsuccessful");			
			
			Command welcomeCommand = new Command();
			welcomeCommand.setName("welcome");
			
			welcomeCommand.putAction(altkeydown_action);
			welcomeCommand.putAction(d_action);
			welcomeCommand.putAction(altkeyup_action);

			ActionScript welcomeAction = new ActionScript();
			welcomeAction.setType("assertcontains");
			welcomeAction.setPara("value", "@vd.message.info.welcome");
			welcomeCommand.putAction(welcomeAction);
			
			welcomeCommand.putAction(assertcleardata_action);
						
			Command menuloginCommand = new Command();
			menuloginCommand.setName("menu.login");
			
			ActionScript menuloginAction = new ActionScript();
			menuloginAction.setType("assertcontains");
			menuloginAction.setPara("value", "@vd.menu.login");
			menuloginCommand.putAction(menuloginAction);	
			
			menuloginCommand.putAction(assertcleardata_action);
			
			Command userloginCommand = new Command();
			userloginCommand.setName("userloginsuccessful");
			
			ActionScript selectuserlogin_action = new ActionScript();
			selectuserlogin_action.setType("inputkey");
			selectuserlogin_action.setPara("value", "1");
			userloginCommand.putAction(selectuserlogin_action);	
			
			ActionScript promptusernameAction = new ActionScript();
			promptusernameAction.setType("assertcontains");
			promptusernameAction.setPara("value", "@vd.action.login.input.userId");
			userloginCommand.putAction(promptusernameAction);
			
			userloginCommand.putAction(assertcleardata_action);
			
			ActionScript inputusernameAction = new ActionScript();
			inputusernameAction.setType("inputkey");
			inputusernameAction.setPara("value", "000000016788");
			userloginCommand.putAction(inputusernameAction);
			
			ActionScript promptpinnumberAction = new ActionScript();
			promptpinnumberAction.setType("assertcontains");
			promptpinnumberAction.setPara("value", "@vd.action.login.input.pinNumber");
			userloginCommand.putAction(promptpinnumberAction);	
			
			userloginCommand.putAction(assertcleardata_action);
			
			ActionScript inputpinnumberAction = new ActionScript();
			inputpinnumberAction.setType("inputkey");
			inputpinnumberAction.setPara("value", "1");
			userloginCommand.putAction(inputpinnumberAction);
			
			ActionScript promptloginsuccessAction = new ActionScript();
			promptloginsuccessAction.setType("assertcontains");
			promptloginsuccessAction.setPara("value", "@vd.action.login.result.successful");
			userloginCommand.putAction(promptloginsuccessAction);	
			
			userloginCommand.putAction(altkeydown_action);
			userloginCommand.putAction(h_action);			
			userloginCommand.putAction(altkeyup_action);
			userloginCommand.putAction(assertcleardata_action);	
			
			userloginsuccessfulTestCase.putCommand(welcomeCommand);						
			userloginsuccessfulTestCase.putCommand(menuloginCommand);
			userloginsuccessfulTestCase.putCommand(userloginCommand);
			
			TestCase userloginfailedTestCase = new TestCase();
			userloginfailedTestCase.setName("userloginfailed");
			
			Command userloginCommand1 = new Command();
			userloginCommand1.setName("userloginfailed");
			

			userloginCommand1.putAction(selectuserlogin_action);	
			
			userloginCommand1.putAction(promptusernameAction);
			
			userloginCommand1.putAction(assertcleardata_action);
			
			userloginCommand1.putAction(inputusernameAction);
			
			userloginCommand1.putAction(promptpinnumberAction);	
			
			userloginCommand1.putAction(assertcleardata_action);
			
			ActionScript inputpinnumber1Action = new ActionScript();
			inputpinnumber1Action.setType("inputkey");
			inputpinnumber1Action.setPara("value", "2");
			userloginCommand1.putAction(inputpinnumber1Action);
			
			ActionScript promptloginfailedAction = new ActionScript();
			promptloginfailedAction.setType("assertcontains");
			promptloginfailedAction.setPara("value", "@vd.action.login.result.failed");
			userloginCommand1.putAction(promptloginfailedAction);	
			
			userloginCommand1.putAction(altkeydown_action);
			userloginCommand1.putAction(h_action);			
			userloginCommand1.putAction(altkeyup_action);
			userloginCommand1.putAction(assertcleardata_action);	
			
			userloginfailedTestCase.putCommand(welcomeCommand);						
			userloginfailedTestCase.putCommand(menuloginCommand);
			userloginfailedTestCase.putCommand(userloginCommand1);
			
			TestCase guestloginsuccessfulTestCase = new TestCase();
			guestloginsuccessfulTestCase.setName("guestloginsuccessful");
			Command guestloginCommand = new Command();
			guestloginCommand.setName("guestloginsuccessful");
			
			ActionScript selectguestlogin_action = new ActionScript();
			selectguestlogin_action.setType("inputkey");
			selectguestlogin_action.setPara("value", "2");
			guestloginCommand.putAction(selectguestlogin_action);	
									
			guestloginCommand.putAction(promptloginsuccessAction);	
			
			guestloginCommand.putAction(altkeydown_action);
			guestloginCommand.putAction(h_action);			
			guestloginCommand.putAction(altkeyup_action);
			guestloginCommand.putAction(assertcleardata_action);			
			guestloginsuccessfulTestCase.putCommand(welcomeCommand);	
			guestloginsuccessfulTestCase.putCommand(menuloginCommand);
			guestloginsuccessfulTestCase.putCommand(guestloginCommand);
			
			TestCase resetTestCase = new TestCase();
			resetTestCase.setName("reset");
			Command resetCommand = new Command();
			resetCommand.setName("reset");
			resetCommand.putAction(altkeydown_action);
			resetCommand.putAction(h_action);			
			resetCommand.putAction(altkeyup_action);			
			resetCommand.putAction(assertcleardata_action);
			resetCommand.putAction(delay5000_action);
			
			resetTestCase.putCommand(resetCommand);
			
			testsuite.putTestCase(initSIPPhoneTestCase);
			testsuite.putTestCase(userloginsuccessfulTestCase);
			testsuite.putTestCase(userloginfailedTestCase);
			testsuite.putTestCase(guestloginsuccessfulTestCase);
			
			testsuite.putTestCase(resetTestCase);
			
			JAXBContext context = JAXBContext.newInstance(testsuite.getClass());
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty("jaxb.formatted.output",new Boolean(true));
			
			// create parent folder if it doesn't exist to avoid IOException
			String path =  "./scripts/aivr_voexo_scripts.xml";
			File file = new File(path);
			if ( file.getParentFile()!=null && !file.getParentFile().exists() ) {
				file.getParentFile().mkdirs();
			}	
			marshaller.marshal(testsuite, file);
			
		}catch(Exception me) {
			Util.getLogger().error("fail to save testsuite "+me);
		}			
	}
	
	public static void generateTestSuite(){
		try {
			TestSuite testsuite = new TestSuite();
			testsuite.setName("test");

			
			JAXBContext context = JAXBContext.newInstance(testsuite.getClass());
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty("jaxb.formatted.output",new Boolean(true));
			
			// create parent folder if it doesn't exist to avoid IOException
			String path =  "./scripts/testsuite.xml";
			File file = new File(path);
			if ( file.getParentFile()!=null && !file.getParentFile().exists() ) {
				file.getParentFile().mkdirs();
			}	
			marshaller.marshal(testsuite, file);
			
		}catch(Exception me) {
			Util.getLogger().error("fail to save testsuite "+me);
		}			
	}
}
